//
//  searchResultTableViewController.m
//  dataGathering
//
//  Created by apple on 14/12/10.
//  Copyright (c) 2014年 shuili. All rights reserved.
//

#import "searchResultTableViewController.h"

@interface searchResultTableViewController ()

@property(nonatomic, retain)workSet *currentWorkset;

@end

@implementation searchResultTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    _currentWorkset = [[currentWorkSetManager sharedInstance] getCurrentWorkSet];
    
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    // Return the number of rows in the section.
    return [_searchResultList count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [[UITableViewCell alloc] initWithFrame:CGRectMake(0, 0, 480, 48)];
    cell.selectionStyle = UITableViewCellSelectionStyleBlue;
    //[cell setSelectedBackgroundView:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"u1123_selected.png"]]];
    
    
    UIColor *typeTextColor = [UIColor colorWithRed:77.0/256.0 green:77.0/256.0 blue:77.0/256.0 alpha:1];
    UIColor *nameTextColor = [UIColor colorWithRed:151.0/256.0 green:151.0/256.0 blue:150.0/256.0 alpha:1];
    
    NSUInteger row = [indexPath row];
    
    UIImageView *view = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"u356.png"]];
    view.frame = CGRectMake(40, 8, 32 , 32);
    view.contentMode = UIViewContentModeScaleAspectFit;
    
    collectedData *cData = [_searchResultList objectAtIndex:row];
    
    UILabel *typeLabel = [[UILabel alloc] initWithFrame:CGRectMake(96, 8, 100 , 19)];
    [typeLabel setText:[cData name]];
    [typeLabel setTextColor:typeTextColor];
    [typeLabel setFont:[UIFont systemFontOfSize:16]];
    
    UILabel *namelabel = [[UILabel alloc] initWithFrame:CGRectMake(96, 28, 200 , 15)];
    [namelabel setText:[cData type]];
    [namelabel setTextColor:nameTextColor];
    [namelabel setFont:[UIFont systemFontOfSize:12]];
    
    [cell addSubview:view];
    [cell addSubview:typeLabel];
    [cell addSubview:namelabel];
    
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (self.selectProtocol || [self.selectProtocol respondsToSelector:@selector(callSearchResultDataDetailView::)]) {
        [self.selectProtocol callSearchResultDataDetailView:[indexPath row] :[[_currentWorkset collectedDataList] objectAtIndex:[indexPath row]]];
    }
}

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
